//package com.ww.springboot.dd.milvus;
//
//import ai.djl.MalformedModelException;
//import ai.djl.Model;
//import ai.djl.inference.Predictor;
//import ai.djl.modality.cv.Image;
//import ai.djl.modality.cv.ImageFactory;
//import ai.djl.modality.cv.transform.Resize;
//import ai.djl.modality.cv.transform.ToTensor;
//import ai.djl.modality.cv.translator.ImageClassificationTranslatorFactory;
//import ai.djl.modality.cv.translator.ImageServingTranslator;
//import ai.djl.repository.zoo.Criteria;
//import ai.djl.repository.zoo.ModelNotFoundException;
//import ai.djl.repository.zoo.ZooModel;
//import ai.djl.translate.Pipeline;
//import ai.djl.translate.TranslateException;
//import ai.djl.translate.Translator;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.IOException;
//import java.nio.file.Files;
//import java.nio.file.Path;
//import java.nio.file.StandardCopyOption;
//
//import ai.djl.training.util.ProgressBar;
//
//public class CreateModelDemo {
//    public static void main(String[] args) throws IOException, TranslateException, MalformedModelException, ModelNotFoundException {
//
//        ImageClassificationService imageClassificationService = new ImageClassificationService();
//
//        imageClassificationService.classifyImage("https://bullfrog-master.oss-cn-shenzhen.aliyuncs.com/delivery_label/20710061711015.pdf");
//    }
//
//
//    public static class ImageClassificationService {
//
//        private final Model model;
//
//        public ImageClassificationService() throws IOException, ModelNotFoundException, MalformedModelException {
//            // 定义模型的准则
//            Criteria<Image, String> criteria = Criteria.builder()
//                    .setTypes(Image.class, String.class)
//                    .optModelName("resnet18_v1")
//                    .optEngine("PyTorch")
//                    .optProgress(new ProgressBar())
//                    .build();
//
//            ""
//            // 加载模型
//            model = criteria.loadModel();
//        }
//
//        public String classifyImage(String url) throws IOException, TranslateException {
//            // 加载图像
//            Image img = ImageFactory.getInstance().fromUrl(url);
//
//            // 预处理图像
//            Pipeline pipeline = new Pipeline();
//            pipeline.add(new Resize(224, 224));
//            pipeline.add(new ToTensor());
//
//            ImageClassificationTranslatorFactory factory = new ImageClassificationTranslatorFactory();
//            Translator<Image, String> translator = factory.newInstance(Image.class, String.class, model
//                    , null);
//
//            // 创建预测器
//            try (Predictor<Image, String> predictor = model.newPredictor(translator)) {
//                // 进行预测
//                String result = predictor.predict(img);
//
//                System.out.println(result);
//                return result;
//            }
//        }
//    }
//}
